package jia.tools;

import jia.game.GenericFlags;
import org.apache.log4j.Logger;
import org.xml.sax.helpers.DefaultHandler;
import org.dom4j.io.XMLWriter;
import org.dom4j.io.OutputFormat;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;



/**
 * **************************************************************************
 * Application:
 * Author: Erik Stell
 * Date: Sep 3, 2004
 * Time: 2:34:16 PM
 * Process:
 * **************************************************************************
 */
public class XMLParser extends DefaultHandler {
    private static final Logger log = Logger.getLogger(XMLParser.class);
    
    public static void main(String argv[]) {

        ArrayList valueArray = new ArrayList();
        valueArray.add("value1");
        valueArray.add("value2");
        valueArray.add("value3");
        valueArray.add("value4");
        valueArray.add("value5");
        valueArray.add("value6");
        
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("root");
        for (int i = 0; i < valueArray.size(); i++) {
            String s = (String)valueArray.get(i).toString();
            root.addElement(s).addText(s);
        }
        
        
        try {
            // lets write to a file
            OutputFormat format = OutputFormat.createPrettyPrint();
            XMLWriter writer = new XMLWriter(new FileWriter("output.xml"), format);
            writer.write(document);
            writer.close();
            
        } catch (IOException e) {
            if (GenericFlags.errorMessages){
                log.error(e.getMessage());
            }
            
        }        
    }
}
